package com.fanketly.funacg2.ui.viewmodels

import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import com.fanketly.funacg2.ui.viewmodels.state.GlobalState
import javax.inject.Inject
import javax.inject.Singleton

/**
 * 统一控制全局的状态，更符合单一责任原则
 * */
@Singleton
class GlobalStates @Inject constructor() {
    private val _globalUiState: MutableState<GlobalState> = mutableStateOf(GlobalState.Close)
    val globalUiState
        get() = _globalUiState.value

    //    fun toDetail() {
//        _globalUiState.value = GlobalState.ToDetail()
//    }
    fun openDrawer() {
        _globalUiState.value = GlobalState.OpenDrawer
    }

    fun setStateClose() {
        _globalUiState.value = GlobalState.Close
    }

    fun showLoading() {
        _globalUiState.value = GlobalState.Loading
    }

    fun showToast(text: String) {
        _globalUiState.value =
            GlobalState.ShowToast(text)
    }

    fun collectState(state: GlobalState) {
        _globalUiState.value = state
    }
}